package model

import (
	"time"

	"gorm.io/gorm"
)

type Post struct {
	gorm.Model
	Title     string    `gorm:"not null;comment:帖子标题"`
	Content   string    `gorm:"type:longtext;not null;comment:帖子内容"`
	Summary   string    `gorm:"type:text;comment:AI生成的摘要"`
	CreatedAt time.Time `gorm:"comment:创建时间"`
	UpdatedAt time.Time `gorm:"comment:更新时间"`
	// 关联关系
	UserID     uint     `gorm:"not null;comment:作者ID"`
	User       User     `gorm:"foreignKey:UserID"`
	CategoryID uint     `gorm:"not null;comment:分类ID"`
	Category   Category `gorm:"foreignKey:CategoryID"`
	Tags       string   `gorm:"comment:标签"`
	Status     int      `gorm:"default:1;comment:状态"`

	// 一对多关系 一个帖子对应多条评论
	Comments []Comment

	// 多对多关系 通过中间表建立关系
	Likes     []User `gorm:"many2many:user_post_likes;comment:点赞用户"`
	Favorites []User `gorm:"many2many:user_post_favorites;comment:收藏用户"`
}
